package controller.frontOffice;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import org.primefaces.model.UploadedFile;

import ejb.author.AuthorService;
import ejb.book.BookService;
import entities.Author;
import entities.Book;
import entities.Category;
import entities.OrderItem;

@Named
@RequestScoped
public class HomeController implements Serializable {

	@EJB
	private BookService bookService;

	private List<Book> books; 
	
	private Book book; 

	public String bookDetails() {

		FacesContext context = FacesContext.getCurrentInstance();  
		Map requestMap = context.getExternalContext().getRequestParameterMap();  
		String bookId1 = (String)requestMap.get("bookId");  
		Long bookId = Long.parseLong(bookId1);		
		setBook(bookService.find(bookId));
		return "bookDetails";
	}
	
	public List<Book> getBooks() {
		return bookService.findAll();
	}

	public void setBooks(List<Book> books) {
		this.books = books;
	}

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}	
	
}
